package com.msb.controller;

import com.msb.model.Person;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


/**
 * @author sunpeng
 * @Date 2021-06-01 17:09
 */
@Controller
public class RequestController {

    //可以直接接受参数，客户端可穿可不穿
    @RequestMapping(value = "/params", method = RequestMethod.GET)
    public String params(String name){
        System.out.println("params:"+name);
        return "success";
    }

    //必传参数：name=sunpeng,id=* 如果不穿会报400，参数不匹配
    @RequestMapping(value = "/params2", method = RequestMethod.GET, params = {"name=sunpeng","id"})
    public String params2(String name){
        System.out.println("params2:"+name);
        return "success";
    }

    // 400: Required String parameter 'name' is not present
    @RequestMapping(value = "/params3")
    public String params3(@RequestParam(value = "name", required = true) String name){
        System.out.println("params3:"+name);
        return "success";
    }

    @RequestMapping(value = "/getBody", method = RequestMethod.GET)
    public String getBody(String id, Person person){
        System.out.println(id);
        System.out.println(person);
        return "success";
    }

    @RequestMapping(value = "/getBody", method = RequestMethod.POST)
    public String postBody(Person person){
        System.out.println(person);
        return "success";
    }
}
